#!/usr/bin/python
# coding=utf-8

from first.date import DatePlot
import os
from second.MysqlFission import MysqlFission
import shutil
import time


class Fission:
    x = []
    y = []
    z = []
    d = []
    def __init__(self):
        print "欢迎使用fission类!"
    # def __init__(self,x,y,z,d):
    # def __init__(self,name):
    # self.name = name
    # print "欢迎使用fission类!"
    def getData(self, name):
        size = 0;
        with open("/Users/Vicky/Documents/workspace/source_api/long/" + name + ".log") as apidata:
            for i in apidata:
                data = i.split("\r\n")[0].split("|")[0]
                low = i.split("\r\n")[0].split("|")[1]
                high = i.split("\r\n")[0].split("|")[2]
                diff = int(high) - int(low)
                self.x.append(data)
                self.y.append(low)
                self.z.append(high)
                self.d.append(diff)
                size += 1;

    def getDataMarkLine(self, name):
        with open("/Users/Vicky/Documents/workspace/source_api/long/" + name + ".log") as apidata:
            for i in apidata:
                data = i.split("\r\n")[0].split("|")
                day = data[0]
                time = float(data[1])
                self.x.append(day)
                self.y.append(time)
        return [self.x, self.y]


if __name__ == "__main__":
    names = []
    for name in names:
        name = u"三沙"
        sql = MysqlFission()
        sql.getWeather(name)
        fission = Fission()
        fission.x = []
        fission.y = []
        fission.z = []
        fission.d = []
        fission.getData(name)
        try:
            DatePlot.MakePlotTwo(fission.x, name, high=fission.y, low=fission.z, diff=fission.d)
        except BaseException:
            print 2
        shutil.copyfile(name + ".html", "/Users/Vicky/Desktop/w/" + name + ".html")
        os.remove(name + ".html")
        time.sleep(5)

# name = u"黄山"
# sql = MysqlFission()
# sql.getWeather(name)
# fission = Fission()
# fission.getData(name)
# try:
#     DatePlot.MakePlotTwo(fission.x, name, high=fission.y, low=fission.z, diff=fission.d)
# except BaseException:
#     print 2
# shutil.copyfile(name+".html","/Users/Vicky/Desktop/w/" + name + ".html")
# os.remove(name+".html")
